<template>
	<view class="content">

		<!-- 搜索部分 -->
		<view class="search_div">
			<view class="search_border">
				<input class="et_word" maxlength="24" placeholder="请输入关键字" :value="word" @input="onInputWord" />
				<view style="color: #ccc;">|</view>
				<view style="padding: 24rpx 36rpx 24rpx 24rpx;" @click.stop="onSearch">搜索</view>
			</view>
		</view>

		<!-- 占位部分 -->
		<view style="width: 100rpx;height: 90rpx;"></view>

		<view class="data_item" v-for="(item,index) in data_list" :key="item.id" @click.stop="onSelItem(item)">
			<view style="display: flex;justify-content: space-between;align-items: center;">
				<view>{{item.company_name || '暂未填写'}}</view>
				<view :class="item.is_audit == 1 ? 'audit_1' : 'audit_0'">{{item.is_audit == 1 ? '已认证✔' : '未认证✖'}}</view>
			</view>
			<view style="margin: 8rpx 0 0 0;color: deepskyblue;display: flex;align-items: center;justify-content: space-between;">
				<view>电话：{{item.servicephone}}</view>
				<image style="width: 44rpx;height: 44rpx;" src="/static/ic_phone.png" @click.stop="onPhone(item)"></image>
			</view>
			<view style="margin: 8rpx 0 0 0;color: #888;display: flex;align-items: center;justify-content: space-between;">
				<view>联系人：{{item.name}}</view>
			</view>
			<view style="height: 1rpx;width: 100%;background-color: #ddd;margin: 16rpx 0 0 0;"></view>
		</view>

		<!-- 空白数据提示 -->
		<view v-if="!data_list || data_list.length <= 0" style="width: 100vw;height: 40vh;line-height: 40vh;text-align: center;">暂无数据~</view>

	</view>
</template>

<script>
	import { getUInfo, timeStr2Timestamp, getCityAndProvince } from '@/util/util.js'
	export default {
		data() {
			return {
				data_list: [],

				page: 1,
				page_size: 20,

				word: '致胜', // 搜索关键字
			}
		},

		mounted() {
			this.getDataList()
		},

		methods: {

			// 拨打电话
			onPhone(item) {
				if (!item || !item.servicephone) {
					uni.showToast({ icon: 'none', title: '未录入号码' })
					return
				}
				uni.makePhoneCall({ phoneNumber: `${item.queryphone}` })
			},

			// 监听:输入关键字
			onInputWord(e) {
				this.word = e.detail.value
			},

			// 点击搜索
			onSearch() {
				this.page = 1
				this.data_list = []
				this.getDataList()
			},

			// 点击选择数据
			onSelItem(item) {
				uni.$emit('onSelCom', { msg: item })
				uni.navigateBack()
			},

			// 下拉刷新
			onPullDownRefresh() {
				this.page = 1
				this.data_list = []
				this.getDataList()
			},

			// 到达底部
			onReachBottom() {
				this.page++
				this.getDataList()
			},

			// 接口:数据列表
			async getDataList() {
				let that = this
				let token = getUInfo().token
				uni.showLoading({ title: '加载中', mask: true, })
				let res = await this.$getLogList({ token, page: this.page, page_size: this.page_size, logistics_name: this.word })
				// console.log('$getLogList.res =', res);
				if (res.code == 1) {
					if (!res.data.data || res.data.data.length <= 0) {
						uni.showToast({ icon: 'none', title: '暂无更多数据' })
						return
					}
					this.data_list = this.data_list.concat(res.data.data)
				} else {
					this.$toast(res.msg)
				}
			},
		}
	}
</script>

<style scoped>
	.content {
		position: relative;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.search_div {
		position: fixed;
		height: 90rpx;
		width: calc(100%);
		background-color: white;
		z-index: 1;
	}

	.search_border {
		display: flex;
		align-items: center;
		width: calc(100% - 48rpx);
		height: calc(100% - 24rpx);
		margin: 12rpx 24rpx 12rpx 24rpx;
		border: solid 1rpx #ccc;
		border-radius: 888rpx;
	}

	.et_word {
		flex-grow: 1;
		padding: 0 0 0 48rpx;
	}

	.data_item {
		display: flex;
		flex-direction: column;
		margin: 20rpx;
		font-size: 28rpx;
	}

	/* 认证状态 */
	.audit_0 {
		color: orangered;
		font-size: 26rpx;
	}

	.audit_1 {
		color: #fdd30d;
		font-size: 26rpx;
	}
</style>